import { Modal, ModalConfig } from '@arco-design/web-vue';

const createModal = (methodName: string, cfg: ModalConfig) => {
  return new Promise((resolve, reject) => {
    Modal[methodName]({
      onOk() {
        resolve(true);
      },
      onCancel() {
        reject(new Error('false'));
      },
      ...cfg,
    });
  });
};

export const warning = (cfg: ModalConfig) => {
  return createModal('warning', {
    hideCancel: false,
    ...cfg,
  });
};

export const info = (cfg: ModalConfig) => {
  return createModal('info', cfg);
};

export const success = (cfg: ModalConfig) => {
  return createModal('success', cfg);
};

export const error = (cfg: ModalConfig) => {
  return createModal('error', cfg);
};

export const confirm = (cfg: ModalConfig) => {
  return createModal('confirm', cfg);
};
const modalPromise = {
  info,
  success,
  error,
  warning,
  confirm,
};

export default modalPromise;
